package xjtu.se.articlecommunity.user.home;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xjtu.se.articlecommunity.common.CommonService;
import xjtu.se.articlecommunity.common.Result;
import xjtu.se.articlecommunity.common.TokenUtils;
import xjtu.se.articlecommunity.common.dto.CurrentUser;
import xjtu.se.articlecommunity.user.home.dto.SearchDto;
import xjtu.se.articlecommunity.user.home.impl.FeedService;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/user/feed")
public class UMainviewAPI {
    @Resource
    FeedService feedService;
    @Resource
    private CommonService commonService;

    @GetMapping("/gettablist")
    public Result getTabList(){
        return Result.success(feedService.returnTabList());
    }

    @GetMapping("/getfeed")
    public Result getFeed(@RequestParam String at_tab){
        log.info("/user/feed/getfeed");
        return Result.success(feedService.returnFeedList(at_tab));
    }

    @GetMapping("/getfollow")
    public Result getartfollow(@RequestHeader("Token") String token){
        CurrentUser currentUser = TokenUtils.getUserInfo(token,commonService);
        return Result.success(feedService.returnFollowFeed(currentUser.getU_id()));
    }

    @GetMapping("/gethot")
    public Result getHotFeed(@RequestParam String line1,@RequestParam String line2){
        return Result.success(feedService.returnHotFeed(line1,line2));
    }

    @PostMapping("/searchart")
    public Result mainSearch(@RequestBody SearchDto searchDto){
        return Result.success(feedService.returnSearchList(searchDto));
    }
}
